<?php
class Resource_SiteMenu extends Zend_Application_Resource_ResourceAbstract
{   
    
    /**
     * Strategy pattern: initialize resource
     *
     * @return mixed
     */
    public function init()
    {
        $tree = Content_Model_Menu::getSiteMenuTree();
        $container = new Zend_Navigation();
        if($tree){
            $page = $this->_createNavigationPagesFromDoctrineTree($tree);
            $container->addPage($page);

            }
        $this->getBootstrap()->bootstrap('View');
        $view = $this->getBootstrap()->getResource('View');
        $view->assign('siteMenu', $container);
    }

    protected function _createNavigationPagesFromDoctrineTree( Content_Model_Menu $menu)
    {
        $page = new Zend_Navigation_Page_Mvc();
        $page->setModule('content');
        $page->setController('menu');
        $page->setAction('index');
        $page->setParams(array('menu_id'=>$menu->id));
        $page->setLabel($menu->title);
        $children = $menu->getNode()->getChildren();

        //$subpages = array();
        if ($children) foreach($children as $child){
            $page->addPage($this->_createNavigationPagesFromDoctrineTree($child));
        }
        return $page;

    }


    public function getSiteMenu()
    {
        /*if (null === $this->_view) {
            $this->_view = new Zend_View($this->getOptions());
            $this->_view->addHelperPath('Areal/View/Helper/', 'Areal_View_Helper');

            Zend_Paginator::setDefaultScrollingStyle('Sliding');
            Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_control.phtml');

        }
        return $this->_view;
         * 
         */

    }
}
